import { store } from "../redux/store"
import { realm, schemaName } from "../utils/schema"

export const formatFriendMsg = () => {
    // const { app } = store.getState()
    // const Array = []
    // app.friendList.forEach((item, index) => {
    //     let MsgLis = realm.objects(schemaName.FriendMsgLis).filtered(`F == ${item.F} and  UserId == ${app.userInfo.Id}`)
    //     if (MsgLis.length > 0) {
    //         let UnreadMsgLis = MsgLis.filtered(`Unread == 1`)
    //         Array.push({ ...item, ...MsgLis[MsgLis.length - 1], Unread: UnreadMsgLis.length })
    //     } else {
    //         Array.push({ ...item, T: 0 })
    //     }
    // })
    // formatFriendApplyMsg()
    return []
}

export const formatGroupMsg = () => {
    // const { app } = store.getState()
    // const Array = []
    // app.groupList.forEach(item => {
    //     let GroupList = realm.objects(schemaName.GroupMsgLis).filtered(`G == ${item.G} and  UserId == ${app.userInfo.Id}`)
    //     if (GroupList.length > 0) {
    //         let UnreadGroupList = GroupList.filtered(`Unread == 1`)
    //         Array.push({ ...GroupList[GroupList.length - 1], ...item, Unread: UnreadGroupList.length })
    //     } else {
    //         Array.push({ ...item, T: 0 })
    //     }
    // })
    return []
}


export const formatFriendApplyMsg = () => {
    // const { app } = store.getState()
    // let some = [];
    // let MsgLis = realm.objects(schemaName.FriendMsgLis).filtered(`UserId == ${app.userInfo.Id} and Unread == 1 and MT == 40 `).sorted('T', true)
    // MsgLis.forEach(el => {
    //     if (!some.some(e => e.F == el.F)) {
    //         const isFriend = app.friendList.find(item => item.F == el.F)
    //         if (!isFriend) {
    //             some.push(el);
    //         }
    //     }
    // });
    // store.dispatch((dispatch) => {
    //     dispatch({ type: 'app/SetFriendApplyMsgMsg', payload: JSON.parse(JSON.stringify(some)) })
    // })
}